/*
 * @Author: qin
 * @Date:   2018-08-28
 * +----------------------------------------------------------------------
 * | admin [ 后台管理系统公共配置信息 ]
 * +----------------------------------------------------------------------
 */
//判断是否必填
var form = {};
window.formVerifyFlag = true;
window.formVerifyFun = function () {
    $('.layui-colla-content').addClass('layui-show');//默认展开所有折叠
    formVerifyFlag = true;
    $('#submit').click();
    return formVerifyFlag;
};
layui.define([
    'jquery',
    'configure',
    'sessionFun',
    'moduleApi',
    'table',
    'form',
    'laydate',
    'jsDictFile',
    'matchDict',
    'bluebird',
    'allHeight',
    'tableMerge',
    'json'
], function (exports) {
    var $ = layui.jquery;
    var configure = layui.configure;
    var sessionFun = layui.sessionFun;
    var moduleApi = layui.moduleApi;
    var table = layui.table;
    form = layui.form;
    var laydate = layui.laydate;
    var jsDictFile = layui.jsDictFile;
    var allHeight = layui.allHeight;
    var matchDict = layui.matchDict;
    var tableMerge = layui.tableMerge;
    //获取token
    try {
        var token = sessionFun.get(configure.SESSION_TOKEN) ? sessionFun.get(configure.SESSION_TOKEN).token : '';
    } catch (err) {
        sessionFun.clear();
        window.sessionStorage.removeItem('curmenu');
        window.sessionStorage.removeItem('menu');
        top.location.href = layui.cache.host;
    }
    //有引入iframe的页面 在iframe页渲染完后需要重新计算它在父页面的高度（多在引用附件的时候使用）
    window.resetIframeH = function (name, h) {
        $('iframe[name=' + name + ']').css('min-height', h + 'px');
    };
    //表单验证
    form.verify({
        isEmpty: function (value, item) {
            var $parentTr = $(item).closest('tr');
            if (!$parentTr.is(':hidden')) {
                if ($(item).attr('type') == 'checkbox') {
                    var checkName = $(item).attr('name');
                    if ($('input[name="' + checkName + '"]:checked').length == 0) {
                        window.formVerifyFlag = false;
                        return '多选框不能为空';
                    }
                }
                if (!($.trim(value))) {
                    window.formVerifyFlag = false;
                    return '必填项不能为空';
                }
            }
        },
        uname: function (value, item) {
            if (value) {
                if (new RegExp('[`~!@$%^&*()+=|{}\':;\',\\[\\].<>/?~！@￥%……&*（）——+|{}【】‘；：”“’。，、？]').test(value)) {
                    window.formVerifyFlag = false;
                    return '不能有特殊字符';
                }
            }
        }, cn: function (value, item) {
            if (value) {
                if (!new RegExp('^[\u4e00-\u9fa5]+$').test(value)) {
                    window.formVerifyFlag = false;
                    return '只能输入中文';
                }
            }
        }, znNum: function (value, item) {
            if (!new RegExp('^[0-9a-zA_Z]+$').test(value)) {
                window.formVerifyFlag = false;
                return '只能输入英文和数字';
            }
        }, upass: function (value, item) {
            if (value) {
                if (new RegExp('[/^[\\S]{6,12}$/]').test(value)) {
                    window.formVerifyFlag = false;
                    return '密码必须6到12位，且不能出现空格';
                }
            }
        }, identity: function (value, item) {
            if (value) {
                // 加权因子
                var weight_factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
                // 校验码
                var check_code = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
                var code = value + "";
                var last = value[17]; //最后一个
                var seventeen = code.substring(0, 17);
                // ISO 7064:1983.MOD 11-2
                // 判断最后一位校验码是否正确
                var arr = seventeen.split("");
                var len = arr.length;
                var num = 0;
                for (var i = 0; i < len; i++) {
                    num = num + arr[i] * weight_factor[i];
                }

                // 获取余数
                var resisue = num % 11;
                var last_no = check_code[resisue];

                // 格式的正则
                // 正则思路
                /*
                第一位不可能是0
                第二位到第六位可以是0-9
                第七位到第十位是年份，所以七八位为19或者20
                十一位和十二位是月份，这两位是01-12之间的数值
                十三位和十四位是日期，是从01-31之间的数值
                十五，十六，十七都是数字0-9
                十八位可能是数字0-9，也可能是X
                */
                var idcard_patter = /^[1-9][0-9]{5}([1][9][0-9]{2}|[2][0][0|1][0-9])([0][1-9]|[1][0|1|2])([0][1-9]|[1|2][0-9]|[3][0|1])[0-9]{3}([0-9]|[X])$/;
                // 判断格式是否正确
                var format = idcard_patter.test(value);
                // 返回验证结果，校验码和格式同时正确才算是合法的身份证号码
                if (!(last === last_no && format)) {
                    window.formVerifyFlag = false;
                    return '身份证号格式有误，请重新填写！';
                }
            }
        }, linkPhone: function (value, item) {
            if (value) {
                var phone = value;
                var regMobilePhone = new RegExp(/^1[34578]\d{9}$/);
                var regTelephone = new RegExp(/^((0\d{2,3})-?)(\d{7,8})(-(\d{3,}))?$/);
                if (!(regMobilePhone.test(phone) || regTelephone.test(phone))) {
                    window.formVerifyFlag = false;
                    return '电话号码格式有误,请重新输入!';
                }
            }
        }, email: function (value, item) {
            if (value) {
                var regEmail = new RegExp(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/);
                if (!regEmail.test(value)) {
                    window.formVerifyFlag = false;
                    return '邮箱格式错误';
                }
            }
        }
    });

    // placeholder 兼容ie8

    if (!('placeholder' in document.createElement('input'))) {
        $('.searchForm input[placeholder],.searchForm textarea[placeholder]').each(function () {
            var that = $(this),
                text = that.attr('placeholder');
            if (that.val() === '') {
                that.val(text).addClass('placeholder');
            }
            that.focus(function () {
                if (that.val() === text) {
                    that.val('').removeClass('placeholder');
                }
            }).blur(function () {
                if (that.val() === '') {
                    that.val(text).addClass('placeholder');
                }
            }).closest('form').submit(function () {
                if (that.val() === text) {
                    that.val('');
                }
            });
        });
    }

    //封装公共方法
    var configureCom = {
        token: token,
        errFun: function (data) {
            if (data.code == 0) {
            } else if (data.status === 401) {
                sessionFun.clear();
                layer.msg('登录超时，请重新登录！');
                window.sessionStorage.removeItem('curmenu');
                window.sessionStorage.removeItem('menu');
                top.location.href = layui.cache.host;
            } else if (data.code === 401) {
                sessionFun.clear();
                layer.msg('登录超时，请重新登录！');
                window.sessionStorage.removeItem('curmenu');
                window.sessionStorage.removeItem('menu');
                top.location.href = layui.cache.host;
            } else {
                top.layer.msg(data.msg);
            }
        },
        //几种默认弹窗样式
        Psize1: ['900px', '600px'],
        Psize2: ['700px', '500px'],
        Psize3: ['500px', '400px'],
        Psize4: ['900px', '500px'],
        Psize5: ['700px', '400px'],
        Psize100: ['100%', '100%'],

        tableHeight: 'full-100',
        limit: 10,
        limits: [1, 5, 8, 10, 15, 20, 100],

        getToken: function () {
            return (sessionFun.get(configure.SESSION_TOKEN) ? sessionFun.get(configure.SESSION_TOKEN).token : '');
        },
        /**
         * TODO:公有方法
         */
        putDataAjax: function (url, data) {
            return new Promise(function (resolve, reject) {
                data = $.extend(data, {token: token});
                var index = top.layer.load(1, {shade: 0.01});
                $.ajax({
                    url: url,
                    type: 'put',
                    cache: false,
                    headers: {
                        //Bearer是我的项目需要的,你可以按你的需求规范格式
                        'Authorization': token
                    },
                    data: data,
                    dataType: 'json',
                    success: function (data) {
                        top.layer.close(index);
                        configureCom.errFun(data);
                        if (data.code == 0) {
                            resolve(data);
                        } else {
                            return false;
                        }
                    },
                    error: function (data) {
                        configureCom.errFun(data);
                        reject(data);
                        top.layer.close(index);
                    }
                });
            });
        },
        putAjax: function (url, data) {
            return new Promise(function (resolve, reject) {
                data = $.extend(data, {token: token});
                var index = top.layer.load(1, {shade: 0.01});
                $.ajax({
                    url: url,
                    type: 'put',
                    cache: false,
                    headers: {
                        //Bearer是我的项目需要的,你可以按你的需求规范格式
                        'Authorization': token
                    },
                    contentType: 'application/json',
                    data: data,
                    dataType: 'json',
                    success: function (data) {
                        top.layer.close(index);
                        configureCom.errFun(data);
                        if (data.code == 0) {
                            resolve(data);
                        } else {
                            return false;
                        }
                    },
                    error: function (data) {
                        configureCom.errFun(data);
                        reject(data);
                        top.layer.close(index);
                    }
                });
            });
        },
        postAjax: function (url, data) {
            return new Promise(function (resolve, reject) {
                // data = $.extend(data, {token: token});
                data = JSON.stringify(data);
                var index = top.layer.load(1, {shade: 0.01});
                $.ajax({
                    url: url,
                    type: 'post',
                    cache: false,
                    headers: {
                        'token': token
                    },
                    contentType: 'application/json',
                    data: data,
                    dataType: 'json',
                    success: function (data) {
                        top.layer.close(index);
                        configureCom.errFun(data);
                        if (data.code == 0) {
                            resolve(data);
                        } else {
                            return false;
                        }
                    },
                    error: function (data) {
                        reject(data);
                        top.layer.close(index);
                    }
                });
            });
        },
        noloadpostAjax: function (url, data) {
            return new Promise(function (resolve, reject) {
                // data = $.extend(data, {token: token});
                data = JSON.stringify(data);
                $.ajax({
                    url: url,
                    type: 'post',
                    cache: false,
                    headers: {
                        'token': token
                    },
                    contentType: 'application/json',
                    data: data,
                    dataType: 'json',
                    success: function (data) {
                        configureCom.errFun(data);
                        if (data.code == 0) {
                            resolve(data);
                        } else {
                            return false;
                        }
                    },
                    error: function (data) {
                        reject(data);
                    }
                });
            });
        },
        postDataAjax: function (url, data) {
            return new Promise(function (resolve, reject) {
                data = $.extend(data, {token: token});
                var index = top.layer.load(1, {shade: 0.01});
                $.ajax({
                    url: url,
                    type: 'post',
                    cache: false,
                    headers: {
                        //Bearer是我的项目需要的,你可以按你的需求规范格式
                        'token': token
                    },
                    // contentType: 'application/json',
                    data: data,
                    dataType: 'json',
                    success: function (data) {
                        top.layer.close(index);
                        configureCom.errFun(data);
                        if (data.code == 0) {
                            resolve(data);
                        } else {
                            return false;
                        }
                    },
                    error: function (data) {
                        top.layer.close(index);
                        configureCom.errFun(data);
                        reject(data);
                    }
                });
            });
        },
        getAjax: function (url, data) {
            return new Promise(function (resolve, reject) {
                data = $.extend(data, {token: token});
                var index = top.layer.load(1, {shade: 0.01});
                $.ajax({
                    url: url,
                    type: 'get',
                    cache: false,
                    headers: {
                        //Bearer是我的项目需要的,你可以按你的需求规范格式
                        'Authorization': token
                    },
                    data: data,
                    dataType: 'json',
                    success: function (data) {
                        top.layer.close(index);
                        configureCom.errFun(data);
                        if (data.code == 0) {
                            resolve(data);
                        } else {
                            return false;
                        }
                    },
                    error: function (data) {
                        configureCom.errFun(data);
                        top.layer.close(index);
                        reject(data);
                    }
                });
            });
        },
        deleteAjax: function (url, data) {
            return new Promise(function (resolve, reject) {
                data = $.extend(data, {token: token});
                var index = top.layer.load(1, {shade: 0.01});
                $.ajax({
                    url: url,
                    type: 'delete',
                    cache: false,
                    headers: {
                        //Bearer是我的项目需要的,你可以按你的需求规范格式
                        'Authorization': token
                    },
                    data: data,
                    dataType: 'json',
                    success: function (data) {
                        top.layer.close(index);
                        configureCom.errFun(data);
                        if (data.code == 0) {
                            resolve(data);
                        } else {
                            return false;
                        }
                    },
                    error: function (data) {
                        configureCom.errFun(data);
                        top.layer.close(index);
                        reject(data);
                    }
                });
            });
        },

        /**
         * 获取url地址中的page参数方法
         */
        GetQueryString: function (name) {
            var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
            var r = window.location.search.substr(1).match(reg);
            if (r !== null) {
                return r[2];
            } else {
                return null;
            }
        },

        /**
         * 判断当前时间位于月份、季度、年
         */
        timeType: function () {
            var today = new Date();//获取当前时间
            var year = today.getFullYear();
            var month = today.getMonth() + 1;
            var quarter = 1;
            if (month < 4) {
                quarter = 1;
            } else if (month < 7) {
                quarter = 2;
            } else if (month < 10) {
                quarter = 3;
            } else {
                quarter = 4;
            }
            return {year: year, month: month, quarter: quarter};
        },

        /**
         * 行边框表格类型
         */
        tableLineBorder: function (url, data, cols, tableId, size, height) {
            var _height = height ? height : 'full-100';
            var _elem = tableId ? '#' + tableId : '#dataList';
            var _tableId = tableId ? tableId : 'dataList';
            var _limit = size || configureCom.limit;
            return new Promise(function (resolve, reject) {
                //表格实例
                table.render({
                    elem: _elem,
                    url: moduleApi.BASE_API + url + '?_='+ new Date().getTime(),//数据接口
                    method: 'post',
                    // height: _height,
                    cellMinWidth: 80,
                    loading: true,
                    skin: 'line',
                    page: {
                        prev: '上一页',
                        next: '下一页',
                        layout: ['prev', 'page', 'next']
                    }, //是否开启分页
                    height: _height,
                    headers: {
                        'token': token
                    },
                    request: {
                        limitName: 'size' //每页数据量的参数名，默认：limit
                    },
                    limit: _limit,
                    limits: configureCom.limits,
                    where: data,
                    parseData: function (res) { //res 即为原始返回的数据
                        return {
                            'code': res.code, //解析接口状态
                            'msg': res.msg, //解析提示文本
                            'count': res.page.total, //解析数据长度
                            'data': res.page.records //解析数据列表
                        };
                    },
                    response: {
                        statusName: 'code', //数据状态的字段名称，默认：code
                        statusCode: 0, //成功的状态码，默认：0
                        msgName: 'msg', //状态信息的字段名称，默认：msg
                        countName: 'count', //数据总数的字段名称，默认：count
                        dataName: 'data' //数据列表的字段名称，默认：data
                    },
                    cols: cols,
                    id: _tableId,
                    even: false,
                    done: function (res, curr, count) {
                        //重设表格高度
                        // var boxH = $('.layui-table-box').height();
                        // var pageH = $('.layui-table-page').height() + 8;
                        // var viewH = boxH + pageH;
                        $(_elem).parent('.panelContent').find('.layui-table-view').css('height', '100%');
                        //$('.layui-table-view').attr('style', 'height:' + viewH + 'px;');
                        resolve({code: 1, msg: '', result: res, count: count});
                    }
                });
            });
        },

        /**
         * 无边框表格类型
         * */
        tableRenderPanel: function (url, data, cols, tableId, size, height) {
            var _height = height ? height : 'full-100';
            var _elem = tableId ? '#' + tableId : '#dataList';
            var _tableId = tableId ? tableId : 'dataList';
            var _limit = size || configureCom.limit;
            return new Promise(function (resolve, reject) {
                //表格实例
                table.render({
                    elem: _elem,
                    url: moduleApi.BASE_API + url + '?_='+ new Date().getTime(),//数据接口
                    method: 'post',
                    // height: _height,
                    cellMinWidth: 80,
                    loading: true,
                    skin: 'nob',
                    page: {
                        prev: '上一页',
                        next: '下一页',
                        layout: ['prev', 'page', 'next']
                    }, //是否开启分页
                    height: _height,
                    headers: {
                        'token': token
                    },
                    request: {
                        limitName: 'size' //每页数据量的参数名，默认：limit
                    },
                    limit: _limit,
                    limits: configureCom.limits,
                    where: data,
                    parseData: function (res) { //res 即为原始返回的数据
                        return {
                            'code': res.code, //解析接口状态
                            'msg': res.msg, //解析提示文本
                            'count': res.page.total, //解析数据长度
                            'data': res.page.records //解析数据列表
                        };
                    },
                    response: {
                        statusName: 'code', //数据状态的字段名称，默认：code
                        statusCode: 0, //成功的状态码，默认：0
                        msgName: 'msg', //状态信息的字段名称，默认：msg
                        countName: 'count', //数据总数的字段名称，默认：count
                        dataName: 'data' //数据列表的字段名称，默认：data
                    },
                    cols: cols,
                    id: _tableId,
                    even: false,
                    done: function (res, curr, count) {
                        //重设表格高度
                        // var boxH = $('.layui-table-box').height();
                        // var pageH = $('.layui-table-page').height() + 8;
                        // var viewH = boxH + pageH;
                        $(_elem).parent('.panelContent').find('.layui-table-view').css('height', '100%');
                        // $('.layui-table-view').attr('style', 'height:' + viewH + 'px;');
                        resolve({code: 1, msg: '', result: res, count: count});
                    }
                });
            });
        },

        /**
         * 表格重载
         */
        tableReloadPanel: function (isrefrash, data, url, tableFilter) {
            if (isrefrash) {
                //刷新（留在当前页）
                table.reload(tableFilter, {
                    url: url,
                    where: data
                });
            } else {
                //刷新（并跳转到第一页）
                table.reload(tableFilter, {
                    url: url,
                    where: data,
                    page: {
                        curr: 1
                    }
                });
            }
        },
        /*
        * 表格合并单元格-自定义数据
        *
        * */
        tableMergeFun: function (cols, data, tableId, height) {
            var _height = height ? height : allHeight.count('.searchForm', '#dataList');
            table.render({
                elem: ('#' + tableId) || '#dataList',
                height: _height,
                method: 'post',
                data: data,
                cellMinWidth: 80,
                headers: {
                    'token': token
                },
                cols: cols,
                limit: data.length,
                done: function () {
                    tableMerge.render(this)
                }
            })
        },
        /**
         * 表格初始化
         * method: 'post'
         * @param url 接口地址
         * @param data 参数
         * @param cols 列表项
         * @param tableId 关联的dom Id
         * @param size 每页显示的条数
         * @param height 高度
         * @returns {*}
         */
        tableRender: function (url, data, cols, tableId, size, height, toolbar) {
            var _height = height ? height : allHeight.count('.searchForm', '#dataList');
            var _elem = tableId ? '#' + tableId : '#dataList';
            var _tableId = tableId ? tableId : 'dataList';
            var _limit = size || configureCom.limit;
            var _toolbar = toolbar ? '#' + toolbar : false;
            data = $.extend(data, {token: token});
            return new Promise(function (resolve, reject) {
                //表格实例
                table.render({
                    elem: _elem,
                    url: moduleApi.BASE_API + url + '?_='+ new Date().getTime(),//数据接口
                    method: 'post',
                    toolbar: _toolbar,
                    // height: _height,
                    cellMinWidth: 80,
                    loading: true,
                    height: _height,
                    page: true, //是否开启分页
                    headers: {
                        'token': token
                    },
                    request: {
                        pageName: 'currPage', //页码的参数名称，默认：page
                        limitName: 'limit' //每页数据量的参数名，默认：limit
                    },
                    limit: _limit,
                    limits: configureCom.limits,
                    where: data,
                    parseData: function (res) { //res 即为原始返回的数据
                        return {
                            'code': res.code, //解析接口状态
                            'msg': res.msg, //解析提示文本
                            'count': res.page.total, //解析数据长度
                            'data': res.page.records //解析数据列表
                        };
                    },
                    response: {
                        statusName: 'code', //数据状态的字段名称，默认：code
                        statusCode: 0, //成功的状态码，默认：0
                        msgName: 'msg', //状态信息的字段名称，默认：msg
                        countName: 'count', //数据总数的字段名称，默认：count
                        dataName: 'data' //数据列表的字段名称，默认：data
                    },
                    cols: cols,
                    id: _tableId,
                    even: true,
                    done: function (res, curr, count) {
                        /*//重设表格高度
                        var boxH = $('.layui-table-box').height();
                        var pageH = $('.layui-table-page').height() + 8;
                        var viewH = boxH + pageH;
                        $('.layui-table-view').attr('style', 'height:' + viewH + 'px;');
                        //表格行样式
                        // $('.layui-table tr:nth-child(even)').css('background-color', '#f2f2f2');*/
                        resolve({code: 1, msg: '', result: res, count: count});
                    }
                });
            });
        },

        pageReqData: function(pageable){
            return pageable ? {
                pageName: 'currPage',
                limitName: 'limit'
            }:{
                pageName: '_p',
                limitName: '_l'
            }

        },

        parseData: function(res , pageable){
            return pageable ? {
                'code': res.code, //解析接口状态
                'msg': res.msg, //解析提示文本
                'count': res.page.total, //解析数据长度
                'data': res.page.records //解析数据列表
            }:{
                'code': res.code, //解析接口状态
                'msg': res.msg, //解析提示文本
                'data': res.list //解析数据列表
            }
        },

        /**
         * g
         * @param url
         * @param data
         * @param cols
         * @param tableId
         * @param size
         * @param height
         * @param toolbar
         * @param page
         * @returns {Promise<any>}
         */
        tableRenderGet: function (url, data, cols, tableId, size, height, toolbar, page) {
            var _tableId = tableId ? tableId : 'dataList';
            var _elem = '#' + _tableId;
            var _height = height ? height : allHeight.count('.searchForm', _elem);
            //var _elem = tableId ? '#' + tableId : '#dataList';

            var _limit = size || configureCom.limit;
            var _toolbar = toolbar ? '#' + toolbar : false;
            var _page = page===false?false :true;
            data = $.extend(data, {token: token});
            return new Promise(function (resolve, reject) {
                //表格实例
                table.render({
                    elem: _elem,
                    url: moduleApi.BASE_API + url + '?_='+ new Date().getTime(),//数据接口
                    method: 'get',
                    toolbar: _toolbar,
                    height: _height,
                    cellMinWidth: 80,
                    loading: true,
                    page: _page, //是否开启分页
                    headers: {
                        'token': token
                    },
                    request: configureCom.pageReqData(_page),
                    limit: _limit,
                    limits: configureCom.limits,
                    where: data,
                    parseData: function (res) { //res 即为原始返回的数据
                        return configureCom.parseData(res, _page)
                    },
                    response: {
                        statusName: 'code', //数据状态的字段名称，默认：code
                        statusCode: 0, //成功的状态码，默认：0
                        msgName: 'msg', //状态信息的字段名称，默认：msg
                        countName: 'count', //数据总数的字段名称，默认：count
                        dataName: 'data' //数据列表的字段名称，默认：data
                    },
                    cols: cols,
                    id: _tableId,
                    even: true,
                    done: function (res, curr, count) {
                        /*//重设表格高度
                        var boxH = $('.layui-table-box').height();
                        var pageH = $('.layui-table-page').height() + 8;
                        var viewH = boxH + pageH;
                        $('.layui-table-view').attr('style', 'height:' + viewH + 'px;');
                        //表格行样式
                        // $('.layui-table tr:nth-child(even)').css('background-color', '#f2f2f2');*/
                        resolve({code: 1, msg: '', result: res, count: count});
                    }
                });
            });
        },

        /**
         * 自定义返回数据表格初始化
         * @param searchData
         * @param cols
         * @param data
         * @param tableId
         * @param height
         * @param toolbarFlag
         * @returns {Promise<any>}
         */
        tableRenderUserDefined: function (searchData, cols, data, tableId, height, toolbarFlag) {
            toolbarFlag = toolbarFlag ? '#toolbarOrg' : false;
            return new Promise(function (resolve, reject) {
                //表格实例
                table.render({
                    height: height,
                    elem: ('#' + tableId) || '#dataList',
                    toolbar: toolbarFlag,
                    where: searchData,
                    data: data,
                    // height: configureCom.tableHeight,
                    cellMinWidth: 80,
                    loading: true,
                    page: false, //是否开启分页
                    limit: configureCom.limit,
                    limits: configureCom.limits,
                    cols: cols,
                    id: tableId || 'dataList',
                    // skin: 'row',
                    even: true,
                    done: function (res, curr, count) {
                        //表格行样式
                        // $('.layui-table tr:nth-child(even)').css('background-color', '#f2f2f2');
                        resolve({code: 1, msg: '', result: res});
                    }
                });
            });
        },

        /**
         * 不分页表格
         * @param url
         * @param data
         * @param cols
         * @returns {Promise<any>}
         */
        tableRenderNoPage: function (url, data, cols) {
            return new Promise(function (resolve, reject) {
                table.render({
                    elem: '#dataList',
                    url: moduleApi.BASE_API + url,//数据接口
                    method: 'get',
                    // height: '',
                    cellMinWidth: 80,
                    loading: true,
                    page: false, //是否开启分页
                    headers: {
                        'token': token
                    },
                    where: data,
                    parseData: function (res) { //res 即为原始返回的数据
                        return {
                            'code': res.code, //解析接口状态
                            'msg': res.msg, //解析提示文本
                            'data': res.list //解析数据列表
                        };
                    },
                    response: {
                        statusName: 'code', //数据状态的字段名称，默认：code
                        statusCode: 0, //成功的状态码，默认：0
                        msgName: 'msg', //状态信息的字段名称，默认：msg
                        dataName: 'data' //数据列表的字段名称，默认：data
                    },
                    cols: cols,
                    id: 'dataList',
                    // skin: 'row',
                    even: true,
                    done: function (res, curr, count) {
                        //表格行样式
                        $('.layui-table tr:nth-child(even)').css('background-color', '#f2f2f2');
                        resolve({code: 1, msg: '', result: res, count: res.data});
                    }
                });
            });
        },
        /**
         * 不分页表格
         * @param id
         * @param url
         * @param data
         * @param cols
         * @returns {Promise<any>}
         */
        newtableRenderNoPage: function (id, url, data, cols) {
            return new Promise(function (resolve, reject) {
                table.render({
                    elem: id,
                    url: url,//数据接口
                    method: 'post',
                    // height: '',
                    cellMinWidth: 80,
                    loading: true,
                    page: false, //是否开启分页
                    headers: {
                        'token': token
                    },
                    where: data,
                    parseData: function (res) { //res 即为原始返回的数据
                        return {
                            'code': res.code, //解析接口状态
                            'msg': res.msg, //解析提示文本
                            'data': res.data //解析数据列表
                        };
                    },
                    response: {
                        statusName: 'code', //数据状态的字段名称，默认：code
                        statusCode: 0, //成功的状态码，默认：0
                        msgName: 'msg', //状态信息的字段名称，默认：msg
                        dataName: 'data' //数据列表的字段名称，默认：data
                    },
                    cols: cols,
                    id: 'dataList',
                    // skin: 'row',
                    even: true,
                    done: function (res, curr, count) {
                        //表格行样式
                        $('.layui-table tr:nth-child(even)').css('background-color', '#f2f2f2');
                        resolve({code: 1, msg: '', result: res, count: res.data});
                    }
                });
            });
        },
        /**
         * 表格重载
         * @param isrefrash
         * @param data
         * @param url
         */
        tableReload: function (isrefrash, data, url) {
            if (isrefrash) {
                //刷新（留在当前页）
                table.reload('dataList', {
                    url: url,
                    where: data
                });
            } else {
                //刷新（并跳转到第一页）
                table.reload('dataList', {
                    url: url,
                    where: data,
                    page: {
                        curr: 1
                    }
                });
            }
        },

        /**
         * 表格刷新
         * @param tableId
         * @author ganyimeng
         */
        tableReloadById: function (tableId) {
            table.reload(tableId)
        },


        //表格排序
        tableSort: function () {
            table.on('sort(dataList)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
                table.reload('dataList', {
                    initSort: obj,//记录初始排序，如果不设的话，将无法标记表头的排序状态。 layui 2.1.1 新增参数
                    where: { //请求参数（注意：这里面的参数可任意定义，并非下面固定的格式）
                        field: obj.field, //排序字段
                        order: obj.type //排序方式
                    }
                });
            });
        },
        // 判断表单input值是否等于他的placeholder
        inptHolder: function (fields) {
            $.each(fields, function (s, k) {
                if ($('input[name=' + s + ']')) {
                    var thatInpt = $('input[name=' + s + ']');
                    var text = thatInpt.attr('placeholder');
                    if (text) {
                        if (text === thatInpt.val()) {
                            fields[s] = '';
                            // delete fields[s];
                        }
                    }
                }
            });
            return fields;
        },
        //表格搜索
        tableSearch: function (addData) {
            form.on('submit(formDemo)', function (data) {
                var fields = configureCom.inptHolder(data.field);
                fields = $.extend(fields, addData);
                table.reload('dataList', {
                    where: fields,
                    page: {
                        curr: 1
                    }
                });
                return false;
            });
        },
        //tab页的表格搜索
        tabSearch: function (url, data, cols) {
            form.on('submit(formDemo)', function (res) {
                var fields = configureCom.inptHolder(res.field);
                console.log(fields);
                var resData = $.extend({}, fields, data);
                configureCom.tableRender(url, resData, cols);
                return false;
            });
        },
        // 判断数组中是否存在重复项
        isRepeat: function (arr) {
            var hash = {};
            var ishas = false;
            for (var i = 0; i < arr.length; i++) {
                if (hash[arr[i]]) {
                    ishas = true;
                }
                hash[arr[i]] = true;
            }
            return ishas;
        },
        //只读表单
        readOnly: function () {
            $('select,button,.klmyDate').attr('disabled', 'disabled').addClass('layui-disabled');
            $('input,select,textarea,button').attr('readonly', 'readonly').addClass('layui-disabled');
            form.render();
        },
        /**
         * @param param [url,title,btn,areaNum,type]
         * @param yes 点击保存以后的回调
         * @param end 关闭回调
         * 设了许多默认值
         */
        klmyPop: function (param, yes, end, success) {
            var url = configureCom.nocache(param[0]);//弹窗页面
            var title = param[1];//标题
            var btn = param[2];//按钮
            var areaNum = [];//弹窗大小
            if (param[3] && (JSON.stringify(param[3]).indexOf('*') > -1)) {
                areaNum = [param[3].split('*')[0] + 'px', param[3].split('*')[1] + 'px'];
            } else {
                areaNum = this['Psize' + (param[3] || 1)];
            }
            var type = param[4] || 2;//弹窗类型

            var layerParam = {};
            layerParam.content = url;
            layerParam.title = title;
            layerParam.maxmin = true;
            if (btn) {
                if (btn !== 0) {
                    if (btn === 1) {
                        layerParam.btn = ['保存'];
                    } else {
                        layerParam.btn = btn;
                    }
                    layerParam.yes = function (index, layero) {
                        if (yes) {//需要回调
                            return yes && yes(index, layero);
                        } else {//点击保存后的 默认方法
                            var iframeWin = top.window.frames['layui-layer-iframe' + index]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                            iframeWin.parWin = window;
                            $(iframeWin.document).find('.demo1').click();
                        }
                    };
                    if (btn.length === 2) {
                        //默认第二个按钮为取消按钮
                        layerParam.btn2 = function (index, layero) {
                            top.layer.close(index);
                        };
                    }
                }
            }
            layerParam.end = function () {
                if (end) {//需要回调
                    return end && end();
                }
            };
            layerParam.cancel = function (index, layero) {
                var iframeWin = top.window.frames['layui-layer-iframe' + index]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                try {
                    iframeWin.removeObject();
                } catch (err) {
                }
            };
            layerParam.success = function (layero, index) {
                var iframeWin = top.window.frames['layui-layer-iframe' + index]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                iframeWin.parWin = window; //父页面
                iframeWin.popIndex = index; //弹窗的index (用于关闭当前弹窗);
                if (success) {
                    return success && success(layero, index);
                }
            };
            layerParam.area = areaNum;
            // layerParam.resize = true;
            layerParam.type = type;
            layerParam.btnAlign = 'c';
            top.layer.open(layerParam);
        },
        //打开tab页子页面
        openTabIframe: function (tabData) {
            localStorage.tabData = JSON.stringify(tabData);
            var url = configure.BASE_TAB_HTML;
            location.href = configureCom.nocache(url);
        },
        //日期
        strToDate: function (date) {
            return date || '';
        },
        //时间 只取 年-月-日
        dateToStr: function (isostr) {
            return isostr.split(' ')[0] || '';
        },
        //时间 年-月-日 时:分:秒
        dateToStrAll: function (isostr) {
            return isostr || '';
        },
        //验证select项 必填
        isSelectEmpty: function () {
            var SelectMsg = '';
            $.each($('select'), function () {
                var td = $(this).parent().prev();
                if (td.attr('class')) {
                    if (!$(this).val() && td.attr('class').indexOf('required') !== '-1') {
                        var name = td.html();
                        SelectMsg = '请选择' + name;
                        return false;
                    }
                }
            });
            if (!$('#city').val() || !$('#country').val()) {
                SelectMsg = '请选择区划';
            }
            return SelectMsg;
        },
        /*
        * TODO：打开pdf盖章页面
        * 需传入url
        * */
        openPdfSign: function (url) {
            top.layer.open({
                type: 2,
                area: configureCom.Psize1,
                content: url,
                btn: ['保存签章', '取消'],
                btnAlign: 'c',
                yes: function (childIndex, childLayero) {
                    var iframeWin = top.window.frames['layui-layer-iframe' + childIndex]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                    iframeWin.signSave().then(function (res) {
                        top.layer.close(childIndex);
                        if (res.code == 1) {
                            top.layer.msg(res.msg);
                        } else {
                            top.layer.alert(res.msg);
                        }
                    });
                }
                /*success: function (layero, index) {
                    top.layer.full(index);
                }*/
            })
        },
        /*
        * TODO：查看合同页面
        * 需传入url
        * */
        openPdfContract: function (url) {
            top.layer.open({
                type: 2,
                area: configureCom.Psize1,
                content: url,
                btn: ['关闭'],
                btnAlign: 'c'
                /*success: function (layero, index) {
                    top.layer.full(index);
                }*/
            })
        },
        /*
        * TODO：打开pdf合格书页面
        * 需传入url
        * */
        openPdfQualified: function (url) {
            top.layer.open({
                type: 2,
                area: configureCom.Psize1,
                content: url,
                btn: ['保存签章', '取消'],
                btnAlign: 'c',
                yes: function (childIndex, childLayero) {
                    var iframeWin = top.window.frames['layui-layer-iframe' + childIndex]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                    iframeWin.signSave().then(function (res) {
                        top.layer.close(childIndex);
                        if (res.code == 1) {
                            top.layer.msg(res.msg);
                        } else {
                            top.layer.alert(res.msg);
                        }
                    });
                }
                /*success: function (layero, index) {
                    top.layer.full(index);
                }*/
            })
        },
        /**
         * 子页面选择功能
         * **/
        childViewSelectFun: function (title, cols, listUrl) {
            return new Promise(function (res, rej) {
                sessionFun.set(configure.SESSION_CHILD_VIEW_SELECT_DATA, {cols: cols, listUrl: listUrl});
                top.layer.open({
                    type: 2,
                    content: configureCom.nocache(configure.COMMON_CHILD_VIEW_SELECT_HTML),
                    area: configureCom.Psize1,
                    title: title,
                    btn: ['选择'],
                    yes: function (index, layero) {
                        var iframeWin = top.window.frames['layui-layer-iframe' + index]; //得到iframe页的窗口对
                        sessionFun.remove(configure.SESSION_CHILD_VIEW_SELECT_DATA);
                        top.layer.close(index);
                        res(iframeWin.getData());
                    }
                });
            });
        },

        /**
         * @type: 选择框字典类型（必填）
         * @optionId: 被选中id（必填）
         * @selectId： 选择器id
         * @url：请求地址（可填）
         * **/
        selectFun: function (type, optionId, selectId, url, param) {
            param = param || 'code';
            var ajaxUrl = url ? url : configure.SEARCH_DICT_HTTP;
            configureCom.postDataAjax(ajaxUrl, {code: type}).then(function (res) {
                var optionHtml = '<option value="">请选择</option>';
                $(res.list).each(function (index, item) {
                    optionHtml += '<option value="' + item[param] + '" ' + (optionId == item[param] ? "selected" : "") + '>' + item.name + '</option>';
                });
                $(selectId).html(optionHtml);
                form.render();
            })
        },
        /**
         * @type: 选择框字典类型（必填）
         * @optionId: 被选中id（必填）
         * @selectId： 选择器id
         * @url：请求地址（可填）
         * **/
        selectDataFun: function (matchDictCode, targetVal, parentId) {
            var list = jsDictFile[matchDictCode][0].childrens;
            var optionHtml = '<option value="">请选择</option>';
            $(list).each(function (index, item) {
                optionHtml += '<option value="' + item.value + '" ' + (targetVal == item.value ? "selected" : "") + '>' + item.name + '</option>';
            });
            $(parentId).html(optionHtml);
            form.render();
        },
        selectDataFun2: function (matchDictCode, targetVal, parentId) {
            var list = jsDictFile[matchDictCode][0].childrens;
            var optionHtml ;
            $(list).each(function (index, item) {
                optionHtml += '<option value="' + item.value + '" ' + (targetVal == item.value ? "selected" : "") + '>' + item.name + '</option>';
            });
            $(parentId).html(optionHtml);
            form.render();
        },
        /** 自定义数据
         * @selectData: 传入对象数组
         * @targetVal: 默认值
         * @parentId： 父容器
         * @name：name值（默认为name，可不填）
         * @value：value值（默认为value，可不填）
         * @type：type（额外用到的参数，可不填）
         * **/
        selectCustomDataFun: function (selectData, targetVal, parentId, name, value, type) {
            name = name || 'name';
            value = value || 'value';
            type = type || '';
            var optionHtml = '<option value="">请选择</option>';
            if ('childrens' in selectData[0]) {
                selectData = selectData[0].childrens;
            }
            $(selectData).each(function (index, item) {
                optionHtml += '<option value="' + item[value] + '" ' + (targetVal == item[value] ? "selected" : "") + ' data-type="' + (item[type] || '') + '">' + item[name] + '</option>';
            });
            $(parentId).html(optionHtml);
            form.render();
        },
        /**
         * select自动完成，返回html
         * @param：code
         * @param：targetVal 默认值
         * **/
        selectReturnOption: function (code, targetVal) {
            var list = jsDictFile[code][0].childrens;
            var html = '<option>请选择</option>';
            $(list).each(function (index, item) {
                html += '<option value="' + item.value + '">' + item.name + '</option>';
            });
            return html;
        },
        /**
         * @type: 多选字典类型（必填）
         * @optionId: 被选中id（必填）
         * @selectId： 选择器id
         * @url：请求地址（可填）
         * **/
        checkboxDataFun: function (matchDictCode, targetVal, parentId) {
            var list = jsDictFile[matchDictCode][0].childrens;
            var valueArr = targetVal && targetVal.split(',');
            var optionHtml = '';
            $(list).each(function (index, item) {
                if (targetVal && valueArr.indexOf(item.value) > -1) {
                    optionHtml += '<input type="checkbox" name="' + parentId + '" class="formData" lay-filter="' + parentId + '" title="' + item.name + '" value="' + item.value + '" checked>';
                } else {
                    optionHtml += '<input type="checkbox" name="' + parentId + '" class="formData" lay-filter="' + parentId + '" title="' + item.name + '" value="' + item.value + '">';
                }
            });
            $('#' + parentId).html(optionHtml);
            form.render();
        },
        throwError: function (msg) {
            throw new Error(msg);
            return;
        },
        /**
         * @type: 单选字典类型（必填）
         * @optionId: 被选中id（必填）
         * @selectId： 选择器id
         * @url：请求地址（可填）
         * **/
        radioDataFun: function (matchDictCode, targetVal, parentId) {
            var list = jsDictFile[matchDictCode][0].childrens;
            var valueArr = targetVal && targetVal.split(',');
            var optionHtml = '';
            $(list).each(function (index, item) {
                if (targetVal && valueArr.indexOf(item.value) > -1) {
                    optionHtml += '<input type="radio" name="' + parentId + '" class="formData" lay-filter="' + parentId + '" title="' + item.name + '" value="' + item.value + '" checked>';
                } else {
                    optionHtml += '<input type="radio" name="' + parentId + '" class="formData" lay-filter="' + parentId + '" title="' + item.name + '" value="' + item.value + '">';
                }
            });
            $('#' + parentId).html(optionHtml);
            form.render();
        },
        /**
         * 类型: 大型人员密集场所
         * @type: 单选字典类型（必填）
         * @optionId: 被选中id（必填）
         * @selectId： 选择器id
         * @url：请求地址（可填）
         * **/
        radioDataFuns: function (matchDictCode, targetVal, parentId) {
            var list = jsDictFile[matchDictCode][0].childrens;
            var valueArr = targetVal && targetVal.split(',');
            var optionHtml = '';
            $(list).each(function (indexFile, itemFile) {
                optionHtml += '<span style="color: #000;float: left; padding: 9px 0px 0px 0px;">' + itemFile.name + '</span>';
                $(itemFile.childrens).each(function (index, item) {
                    if (targetVal && valueArr.indexOf(item.value) > -1) {
                        optionHtml +=
                            '<input type="radio" name="' + parentId + '" class="formData" lay-filter="' + parentId + '" title="' + item.name + '" value="' + item.value + '" checked>';
                    } else {
                        optionHtml +=
                            '<input type="radio" name="' + parentId + '" class="formData" lay-filter="' + parentId + '" title="' + item.name + '" value="' + item.value + '">';
                    }
                });
                optionHtml += '<br>'
            });
            $('#' + parentId).html(optionHtml);
            form.render();
        },
        radioDataFuns2: function (matchDictCode, targetVal, parentId) {
            var list = jsDictFile[matchDictCode][0].childrens;
            var valueArr = targetVal && targetVal.split(',');
            var optionHtml = '';
            $(list).each(function (indexFile, itemFile) {
                $(itemFile.childrens).each(function (index, item) {
                    if(item.value === targetVal){
                        optionHtml += '<span style="color: #000;float: left; padding: 9px 0px 0px 0px;">' + itemFile.name + '</span>';
                        optionHtml += '<input type="radio" value="'+targetVal+'" title="'+item.name+'" checked>';
                    }
                });
            });
            $('#' + parentId).html(optionHtml);
            form.render();
        },
        /**
         * 类型: 其他特殊工程
         * @type: 单选字典类型（必填）
         * @optionId: 被选中id（必填）
         * @selectId： 选择器id
         * @url：请求地址（可填）
         * **/
        radioDataFunsl: function (matchDictCode, targetVal, parentId) {
            var list = jsDictFile[matchDictCode][0].childrens;
            var valueArr = targetVal && targetVal.split(',');
            var optionHtml = '';
            $(list).each(function (indexFile, itemFile) {
                optionHtml += '<span style="color: #000;float: left; padding: 9px 0px 0px 0px;">' + itemFile.name + '</span>';
                if (itemFile.dictId != '0e4f5a8f8bb9a7eb78d95917990e2266') {
                    $(itemFile.childrens).each(function (index, item) {
                        if (targetVal && valueArr.indexOf(item.value) > -1) {
                            optionHtml +=
                                '<input type="radio" name="' + parentId + '" class="formData" lay-filter="' + parentId + '" title="' + item.name + '" value="' + item.value + '" checked>';
                        } else {
                            optionHtml +=
                                '<input type="radio" name="' + parentId + '" class="formData" lay-filter="' + parentId + '" title="' + item.name + '" value="' + item.value + '">';
                        }
                    })
                } else if (itemFile.dictId == '0e4f5a8f8bb9a7eb78d95917990e2266') {
                    $(itemFile.childrens).each(function (index, item) {
                        optionHtml += '<span style="color: #000;float: left; padding: 9px 0px 0px 0px;">' + item.name + '</span>';
                        $(item.childrens).each(function (indexXia, itemXia) {
                            if (targetVal && valueArr.indexOf(item.value) > -1) {
                                optionHtml +=
                                    '<input type="radio" name="' + parentId + '" class="formData" lay-filter="' + parentId + '" title="' + itemXia.name + '" value="' + itemXia.value + '" checked>';
                            } else {
                                optionHtml +=
                                    '<input type="radio" name="' + parentId + '" class="formData" lay-filter="' + parentId + '" title="' + itemXia.name + '" value="' + itemXia.value + '">';
                            }

                        });
                        optionHtml += '<br>'
                    })
                } else {
                }
                optionHtml += '<br>'
            });
            $('#' + parentId).html(optionHtml);
            form.render();
        },
        /*
        * 数据拼接（以逗号分隔）,传入数组
        * @type: 传入需拼接的对象key，可不传
        * */
        dataConcat: function (data, type) {
            type = type || 'id';
            var ids = '';
            $(data).each(function (index, item) {
                if (!index) {
                    ids = item[type];
                } else {
                    ids += ',' + item[type];
                }
            });
            return ids;
        },
        /**
         * 弹出一个错误提示
         * @param {String} msg
         */
        msgError: function (msg) {
            layer.msg(msg, {
                icon: 5
            });
            return;
        },
        isEmpty: function (string) {
            if (!string || string == "null") {
                return "-";
            } else {
                return string;
            }
        },
        //根据不同的审查结论code 返回同颜色审查名称
        getCheckResultTypeDesc: function (code) {
            var color = '';
            if (code !== '1000') {
                color = 'red';
            }
            if (code === '1040') {
                color = '#009688';
            }
            var checkResultTypeDesc = '-';
            //获取结论描述
            $(jsDictFile.checkResultType).each(function (index, item) {
                if (item.value === code) {
                    checkResultTypeDesc = item.name;
                    return true;
                }
            });
            var style = (color ? ('color:' + color) : '');
            return '<span style="' + style + '">' + (checkResultTypeDesc || '-') + ' </span>';
        },
        getAuditOrganType: function (code) {
            //根据编码获取审查机构类型描述
            switch (code) {
                case configure.AUDIT_ORGAN_TYPE.HOUSING_CONSTRUCTION.value:
                    return configure.AUDIT_ORGAN_TYPE.HOUSING_CONSTRUCTION.name;
                case configure.AUDIT_ORGAN_TYPE.FIRE_DEFENCE.value:
                    return configure.AUDIT_ORGAN_TYPE.FIRE_DEFENCE.name;
                case configure.AUDIT_ORGAN_TYPE.PEOPLE_DEFENCE.value:
                    return configure.AUDIT_ORGAN_TYPE.PEOPLE_DEFENCE.name;
                default:
                    return '';
            }
        },
        //获取专业类别描述
        getSpecialTypeDesc: function (code) {
            var sgProjSpecTypeArray = [];
            $(jsDictFile.sgProjSpecType).each(function (index, item) {
                $(item.childrens).each(function (index1, item1) {
                    sgProjSpecTypeArray.push(item1);
                });
            });
            if (code) {
                return matchDict.data(code, sgProjSpecTypeArray).name;
            }
            return '';
        },
        //默认地图选择事件绑定
        defaultMapChooseBind: function () {
            $('.pointChoose').on('click', function () {
                //地图选择
                var pointChoose = $(this);
                layerPop.param.title = '选择位置';
                layerPop.param.btns = ['保存'];
                layerPop.param.isTop = true;
                layerPop.param.url = configure.MAP_TEMPLATE;
                layerPop.param.area = ['900px', '500px'];
                layerPop.param.saveForm = function (_data) {
                    var points = JSON.parse(_data);
                    if (points.lat && points.lng) {
                        pointChoose.find('.detail').text('经度：' + points.lat + ';纬度：' + points.lng);
                        $('#projLat').val(points.lat);
                        $('#projLon').val(points.lng);
                        layerPop.close();
                    }
                    else {
                        top.layer.msg('请重新选择');
                    }
                };
                layerPop.popOneTopFrame();
            });
        },
        //遮罩层弹窗
        loadON: function (msg) {
            top.loading = top.layer.load(1, {
                content: msg || '数据提交中...',
                shade: [0.4, '#393D49'],
                success: function (layero) {
                    layero.css('padding-left', '30px');
                    layero.find('.layui-layer-content').css({
                        'padding-top': '40px',
                        'width': '100px',
                        'background-position-x': '16px'
                    });
                }
            });
        },
        //关闭遮罩层
        loadOff: function () {
            if (top.loading) {
                top.layer.close(top.loading);
            }
        },
        //获取文件名中的后缀名
        getLastName: function (filename) {
            var index1 = filename.lastIndexOf('.');
            var index2 = filename.length;
            var postf = filename.substring(index1, index2);//后缀名
            return postf;
        },
        //拼接提示框title
        confirmRemoveTitle: function (name, typeName) {
            typeName = typeName || '';
            return '<span style="">确认删除【' + name + '】' + typeName + '?</span>';
        },
        smailTobigNum: function (section) {//大小写转换
            var chnNumChar = ['', '一', '二', '三', '四', '五', '六', '七', '八', '九'];
            var chnUnitChar = ['', '十', '百', '千'];
            var strIns = '', chnStr = '';
            var unitPos = 0;
            var zero = true;
            while (section > 0) {
                var v = section % 10;
                if (v === 0) {
                    if (!zero) {
                        zero = true;
                        chnStr = chnNumChar[v] + chnStr;
                    }
                } else {
                    zero = false;
                    strIns = chnNumChar[v];
                    strIns += chnUnitChar[unitPos];
                    chnStr = strIns + chnStr;
                }
                unitPos++;
                section = Math.floor(section / 10);

            }
            return chnStr;
        },
        gotomail: function ($mail) {
            var temp = $mail.split('@');
            var $t = temp[1].toLowerCase();
            if ($t == '163.com') {
                return 'http://mail.163.com';
            } else if ($t == 'vip.163.com') {
                return 'http://vip.163.com';
            } else if ($t == '126.com') {
                return 'http://mail.126.com';
            } else if ($t == 'qq.com' || $t == 'vip.qq.com' || $t == 'foxmail.com') {
                return 'http://mail.qq.com';
            } else if ($t == 'gmail.com') {
                return 'http://mail.google.com';
            } else if ($t == 'sohu.com') {
                return 'http://mail.sohu.com';
            } else if ($t == 'tom.com') {
                return 'http://mail.tom.com';
            } else if ($t == 'vip.sina.com') {
                return 'http://vip.sina.com';
            } else if ($t == 'sina.com.cn' || $t == 'sina.com') {
                return 'http://mail.sina.com.cn';
            } else if ($t == 'tom.com') {
                return 'http://mail.tom.com';
            } else if ($t == 'yahoo.com.cn' || $t == 'yahoo.cn') {
                return 'http://mail.cn.yahoo.com';
            } else if ($t == 'tom.com') {
                return 'http://mail.tom.com';
            } else if ($t == 'yeah.net') {
                return 'http://www.yeah.net';
            } else if ($t == '21cn.com') {
                return 'http://mail.21cn.com';
            } else if ($t == 'hotmail.com') {
                return 'http://www.hotmail.com';
            } else if ($t == 'sogou.com') {
                return 'http://mail.sogou.com';
            } else if ($t == '188.com') {
                return 'http://www.188.com';
            } else if ($t == '139.com') {
                return 'http://mail.10086.cn';
            } else if ($t == '189.cn') {
                return 'http://webmail15.189.cn/webmail';
            } else if ($t == 'wo.com.cn') {
                return 'http://mail.wo.com.cn/smsmail';
            } else if ($t == '139.com') {
                return 'http://mail.10086.cn';
            } else {
                return '';
            }
        },
        //阿拉伯数字转中文数字
        sectionToChinese: function (section) {
            if (null === section || '' === section) {
                return '初审';
            }
            if (section === 1) {
                return '初审';
            } else {
                chnStr = configureCom.smailTobigNum(section);
            }
            return chnStr + '审';
        },
        //单体名称前加项目名
        getMSName: function (d) {
            var manName = d.mainProject ? (d.mainProject.mainProjName || '') : '';
            var proName = d.mainProjectName || d.mainProjName || manName || d.projName || d.projectName || '';
            var sinName = d.singleProjectName || d.singleProjName || d.sgProjName || '';
            return proName + sinName;
        },
        //根据code获取字典中的 name
        getJsName: function (type, code) {
            var name = '';
            $.each(jsDictFile[type], function (index, item) {
                if (item.value === code) {
                    name = item.name;
                    return;
                }
            });
            return name;
        },
        //获取根据name获取字典中的 code
        getJsCode: function (type, name) {
            var code;
            $.each(jsDictFile[type], function (index, item) {
                if (item.name === name) {
                    code = item.value;
                    return;
                }
            });
            return code;
        },
        //获取url中的id 值
        getUrlId: function () {
            window.bdId = '';
            window.kcBdId = '';
            window.sjBdId = '';
            if (configureCom.GetQueryString('bdId')) {
                window.bdId = configureCom.GetQueryString('bdId');
            }
            if (configureCom.GetQueryString('kcBdId')) {
                window.kcBdId = configureCom.GetQueryString('kcBdId');
            }
            if (configureCom.GetQueryString('sjBdId')) {
                window.sjBdId = configureCom.GetQueryString('sjBdId');
            }
            window.singleProjectId = configureCom.GetQueryString('singleProjectId');
        },
        nocache: function (url, iframeId, layerIndex) {//链接上加时间戳，取消缓存
            if (iframeId) {
                iframeId = 'iframeId=' + iframeId + '&';
            } else {
                iframeId = '';
            }
            var time = new Date().getTime();
            var res = '';
            if (url.indexOf('nocache') === -1) {
                if (url.indexOf('?') === -1) {
                    res = url + '?';
                } else {
                    res = url + '&';
                }
                res += iframeId + 'layerIndex=' + layerIndex + '&nocache=' + time;
                return res;
            } else {
                var oldTime = configureCom.GetQueryString('nocache');
                res = url.replace(oldTime, time);
                return res;
            }
        },
        //关闭弹窗
        closeWind: function (pageFlag) {
            pageFlag = pageFlag || false;
            var index = top.layer.getFrameIndex(window.name);
            console.log(index);
            var iframeId = configureCom.GetQueryString('iframeId');
            var iframeWin = top.window.frames['navIframe' + iframeId]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
            try {
                iframeWin.renderTable()
            } catch (err) {
                try {
                    iframeWin.configureCom.tableReload(pageFlag);
                }catch (err) {}
            }
            top.layer.close(index);
        },
        /*
        * 获取数据方法
        * */
        getData: function () {
            return new Promise(function (resolve, reject) {
                $('.layui-tab-content>.layui-tab-item>iframe').each(function (index, item) {
                    try {
                        $(item)[0].contentWindow.getData().then(function (res) {
                            resolve(res);
                        });
                        /*//如果多个标签同时需要保存的话
                        var list = [];
                        $(item)[0].contentWindow.getData().then(function (res) {
                            list.push(res);
                        });
                        resolve(list);*/
                    } catch (err) {
                    }
                });
            })
        },
        getData: function (_index) {
            return new Promise(function (resolve, reject) {
                $('.layui-tab-content>.layui-tab-item>iframe').each(function (index, item) {
                    try {
                        //如果多个标签同时需要保存的话
                       if(_index == index){
                           $(item)[0].contentWindow.getData().then(function (res) {
                               resolve(res)
                           });
                       }
                    } catch (err) {
                    }
                });
            })
        },
        //浏览器检测
        IEVersion: function () {//判断当前浏览器
            var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
            var isIE = userAgent.indexOf('compatible') > -1 && userAgent.indexOf('MSIE') > -1; //判断是否IE<11浏览器
            var isEdge = userAgent.indexOf('Edge') > -1 && !isIE; //判断是否IE的Edge浏览器
            var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf('rv:11.0') > -1;
            if (isIE) {
                var reIE = new RegExp('MSIE (\\d+\\.\\d+);');
                reIE.test(userAgent);
                var fIEVersion = parseFloat(RegExp['$1']);
                if (fIEVersion === 7) {
                    return 7;
                } else if (fIEVersion === 8) {
                    return 8;
                } else if (fIEVersion === 9) {
                    return 9;
                } else if (fIEVersion === 10) {
                    return 10;
                } else {
                    return 6;//IE版本<=7
                }
            } else if (isEdge) {
                return 'edge';//edge
            } else if (isIE11) {
                return 11; //IE11
            } else {
                return -1;//不是ie浏览器
            }
        },
        //删除方法
        deleteFun: function (url, data) {
            return new Promise(function (resolve, reject) {
                configureCom.postDataAjax(url, data).then(function (res) {
                    if (res.code != 0) {
                        top.layer.alert('删除失败！');
                        return false;
                    }
                    resolve(res);
                });
            });
        },
        /**
         * 列表选中删除方法
         * @data:选中对象
         * @itemKey:选中对象需要的key值
         * @dataKey:发送请求需要的key
         * @url:删除接口
         * **/
        deleteListFun: function (data, itemKey, dataKey, url) {
            return new Promise(function(resolve,reject){
                if (!data.length) {
                    top.layer.alert('请您至少选择一条数据后再提交！');
                    return false;
                }
                top.layer.confirm('您真的要删除选中的数据吗？', function (index, layero) {
                    top.layer.close(index);
                    var ids = '';
                    $(data).each(function (index, item) {
                        if (!index) {
                            ids = item[itemKey];
                        } else {
                            ids += ',' + item[itemKey];
                        }
                    });
                    resolve({result:ids});
                    configureCom.postDataAjax(url, ajaxData).then(function (res) {
                        top.layer.msg('删除成功！');
                    })
                });
            });
        },
        /*
        * 判断当前阶段当前视图是否包含勘察设计单位类型
        * */
        orgTypeFun: function (orgTypeCode) {
            var loginData = sessionFun.get(configure.SESSION_LOGIN_INFOR_DATA);//获取登录信息
            var listData = sessionFun.get(configure.SESSION_PROJECT_WAIT_LIST_DATA) || sessionFun.get(configure.SESSION_PROJECT_LIST_DATA);//表单类型
            var loginInforData = loginData.result.org;//登陆企业信息
            var orgType = [];
            //判断当前视图是否包含勘察
            if (('kcCorpId' in listData) && (listData.kcCorpId == loginInforData.orgNo)) {
                orgType.push(configure.KC_CODE);
            }
            //判断当前视图是否包含设计
            if (('sjCorpId' in listData) && (listData.sjCorpId == loginInforData.orgNo)) {
                orgType.push(configure.SJ_CODE);
            }
            //判断是否是建设单位
            if (('buildCorpId' in listData) && (listData.buildCorpId == loginInforData.orgNo)) {
                orgType.push(configure.JSDW_CODE);
            }
            //判断是否是审图单位
            if (('checkOrgId' in listData) && (listData.checkOrgId == loginInforData.orgNo)) {
                orgType.push(configure.STDW_CODE);
            }
            var orgFlag = false;//初始化企业类型判断为false
            if (orgType.indexOf(orgTypeCode) > -1) {//如果包含指定类型，则变为true
                orgFlag = true;
            }
            return orgFlag;
        },
        editItem: function (title, htmlUrl, httpUrl) {
            return new Promise(function (resolve, reject) {
                top.layer.open({
                    type: 2,
                    title: title,
                    area: configureCom.Psize1,
                    content: configureCom.nocache(htmlUrl),
                    btn: ['保存'],
                    yes: function (index, layero) {
                        var iframeWin = top.window.frames['layui-layer-iframe' + index]; //得到iframe页的窗口对
                        var data = iframeWin.getData();
                        if (!data) {
                            return false;
                        }
                        configureCom.postDataAjax(httpUrl, data).then(function (res) {
                            if (res.code != 0) {
                                top.layer.alert('删除失败！');
                                return false;
                            }
                            top.layer.close(index);
                            resolve(res);
                        });
                    }
                });
            });

        }
    };
    exports('configureCom', configureCom);
});
